package com.hellowx_ssm.aop.aspectj;


import com.hellowx_ssm.aop.proxy.Log;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by IntelliJ IDEA.
 *
 * @author MagicMushroom
 * @date 2021/6/8
 */
public class UserServiceImpl implements UserService, ApplicationContextAware {
    private ApplicationContext ctx;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.ctx = applicationContext;
    }

    @Override
    public void register(User user) {
        System.out.println("UserServiceImpl.register");
//        这样会调用到原始方法
//        this.login(new User());
        UserService userService = (UserService) ctx.getBean("userService");
        userService.login(new User());
    }

    @Log
    @Override
    public boolean login(User user) {
        System.out.println("UserServiceImpl.login");
        return false;
    }
}
